<extend name="Home@Base/common" />
<block name="body">
    <div class="span9 page_message">
        <section id="contents"> <include file="Home@Addons/_nav" />
            <div class="tab-content">
                <php> $post_url || $post_url = U('edit?model='.$model['id'], $get_param);</php>
                <form class="form-horizontal form-center" method="post" action="{$post_url}" id="form">

                    <div class="form-item cf">
                        <label class="item-label"> <span class="need_flag">*</span> 费用类型 </label>
                        <div class="controls">
                            <input type="text" readonly="readonly" name="type" value={$data.type}>
                        </div>
                    </div>
                    <empty name="data.isQuotaReimbursement">
                        <div class="form-item cf">
                            <label class="item-label"> <span class="need_flag">*</span> 发票张数 </label>
                            <div class="controls">
                                <input type="text" name="invoiceCount" value={$data.invoiceCount}>
                            </div>
                        </div>
                        <label class='item-label'>图片</label>
                        <div class='controls'>
                            <div class='mult_imgs'>
                                <div class='upload-img-view' id='mutl_picture_pictures'>
                                    <volist name="data.pictures" id="pic">
                                        <div class='upload-pre-item22'>
                                            <img width='100' height='100' src="{$pic.url}"/>
                                            <input type='hidden' name='pictures[]' value="{$pic.id}"/><em>&nbsp;</em>
                                        </div>
                                    </volist>
                                </div>
                                <div class='controls uploadrow2' data-max='9' title='点击上传图片'  rel='pictures'>
                                    <input type='file' id='upload_picture_pictures'>
                                </div>
                            </div>
                        </div>
                    </empty>
                    <if condition="$data.isOtherReimbursement eq 1">
                        <div class="form-item cf">
                            <label class="item-label"> <span class="need_flag">*</span> 附件数量 </label>
                            <div class="controls">
                                <input type="text" name="fileCount" value={$data.fileCount}>
                            </div>
                        </div>
                        <input type="hidden" id="filesIds" name='fileids' value='{$data.fileids}' />
                        <div class="form-item cf">
                            <label class="item-label"><span class="need_flag">*</span>附件上传<span class="check-tips">支持文件格式doc,docx,ppt,pptx,xls,xlsx</span></label>
                            <div class="controls upload_file">
                                <div id="upload_file_files" class="uploadrow_file" ></div>
                                <input type="hidden" name="files" value=""/>
                                <div class="upload-img-box" id="files_box"></div>
                            </div>
                        </div>
                    </if>
                    <empty name="data.isQuotaReimbursement">
                        <div class="form-item cf">
                            <label class="item-label"> <span class="need_flag">*</span> 备注 </label>
                            <div class="controls">
                                <input type="text" value="{$data.description}" name="description" class="text input-large" placeholder="请填用途描述">
                            </div>
                        </div>
                    </empty>
                    <if condition="$data.type eq '授课费'">
                        <div class="form-item cf">
                            <label class="item-label"> <span class="need_flag">*</span> 课时 </label>
                            <div class="controls">
                                <input type="number" id="input_hours" name="hours" value="{$data.hours}">
                            </div>
                        </div>
                        <div class="form-item cf">
                            <label class="item-label"> <span class="need_flag">*</span> 讲课人职称 </label>
                            <div class="controls">
                                <select id="select_teacherLvl" name="teacherLvl" onchange="teacherLevelSel()">
                                  <volist name="data.trainerLevels" id="vo">
                                      <option value="{$vo.id}" {$vo.selected}>{$vo.name}</option>
                                  </volist>
                                </select>
                            </div>
                        </div>
                    </if>
                    <if condition="$data.isMeetingReimbursementOther eq 1">
                        <div class="form-item cf">
                            <label class="item-label"> <span class="need_flag">*</span> 单价 </label>
                            <div class="controls">
                                <input type="number" min="0.0" step="0.01" id="input_price" name="price" value="{$data.price}" onkeyup="calc()">
                            </div>
                        </div>
                        <div class="form-item cf">
                            <label class="item-label"> <span class="need_flag">*</span> 数量 </label>
                            <div class="controls">
                                <input type="number" id="input_quantity" name="quantity" value="{$data.quantity}" onkeyup="calc()">
                            </div>
                        </div>
                    </if>
                    <div class="form-item cf">
                        <label class="item-label"> <span class="need_flag">*</span> 该项总金额 </label>
                        <div class="controls">
                            <input type="number" min="0.0" step="0.01" id="input_total" name="total" value="{$data.total}">
                        </div>
                    </div>
                    <div class="form-item cf">
                        <span style="width: 50%;word-break:normal;display:block;" id="span_std_hint">{$data.standard_hint}</span>
                    </div>
                    <div>
                        <input type="hidden" name="id" value="{$data.id}">
                        <input type="hidden" name="application_id" value={$data.application_id}>
                        <input type="hidden" id="input_tuition_std" name="tuition_std" value={$data.tuition_std}>
                        <input type="hidden" name="dailyStandard" value={$data.dailyStandard}>
                    </div>
                    <div class="form-item form_bh" style="width: 40%">
                        <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal" style="float: left">确 定</button>
                        <button class="btn cancel-btn" id="cancel" style="float: right" name="button_cancel" value=1>取 消</button>
                    </div>
                </form>
            </div>
        </section>
    </div>
</block>

<block name="script">
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript">
        var filesInfo = [];
        var fileUploader = null;
        var fileObjs = [];

        $(function(){
            var UploadFileExts = 'jpg,gif,png,jpeg,zip,rar,tar,gz,7z,doc,docx,txt,xml,xls,xlsx,csv,pem,amr,mp3,mp4,bmp,wma,wav';
            //初始化上传图片插件
            initUploadImg();
            if(UploadFileExts!=''){
                initUploadFile(function(){},UploadFileExts);
            }else{
                initUploadFile();
            }

            fileUploader = initUploadFileWithRemove(fileUploadSuccess)[0];
            init_file_uplaod();

            $('.time').datetimepicker({
                format: 'yyyy-mm-dd hh:ii',
                language:'zh-CN',
                minView:0,
                autoclose:true
            });
            $('.date').datetimepicker({
                format: 'yyyy-mm-dd',
                language:'zh-CN',
                minView:2,
                autoclose:true
            });
            showTab();

            $('.toggle-data').each(function(){
                var data = $(this).attr('toggle-data');
                if(data=='') return true;

                if($(this).is(':selected') || $(this).is(':checked')){
                    change_event(this)
                }
            });
            $('.toggle-data').bind('click',function(){ change_event(this) });
            $('select').change(function(){
                $('.toggle-data').each(function(){
                    var data = $(this).attr('toggle-data');
                    if(data=='') return true;

                    if($(this).is(':selected') || $(this).is(':checked')){
                        change_event(this)
                    }
                });
            });
        });

        // upload files
        //上传附件组件
        function init_file_uplaod () {
            var tmp = $('#filesIds').val();
            if (tmp != ''){
                filesInfo = JSON.parse(tmp);
            }

            var box_html = "<div class=\"upload-pre-file\">";
            console.log(filesInfo.length);
            for (let i = 0; i < filesInfo.length; i++) {
                console.log(filesInfo[i]);
                box_html += "<span class=\"upload_icon_all\"></span>" + filesInfo[i].name;
                box_html += "<span class=\"emoji emoji274c\" onclick=\"delFile(" + i +")\"></span>";
            }
            box_html += "</div>"
            document.getElementById('files_box').innerHTML = box_html;
        }

        function fileUploadSuccess(file,data, name){
            if(data.status){
                filesInfo.push({
                    id: data.id,
                    name: data.name
                })
                fileObjs.push(file)
                var tmp = JSON.stringify(filesInfo);
                $('#filesIds').val(tmp);

                var box_html = "<div class=\"upload-pre-file\">";
                console.log(filesInfo);
                for (let i = 0; i < filesInfo.length; i++) {
                    box_html += "<span class=\"upload_icon_all\"></span>" + filesInfo[i].name;
                    box_html += "<span class=\"emoji emoji274c\" onclick=\"delFile(" + i + ")\"></span>";
                }
                box_html += "</div>"

                $("input[name="+name+"]").parent().find('.upload-img-box').html(box_html);
            }
        }

        function delFile (index) {
            console.log('delFile');
            fileUploader.removeFile(fileObjs[index]);
            fileObjs.splice(index,1);
            filesInfo.splice(index,1);
            var tmp = JSON.stringify(filesInfo);
            $('#filesIds').val(tmp);
            document.getElementById('files_box').innerHTML = '';
            var box_html = "<div class=\"upload-pre-file\">";
            console.log(filesInfo.length);
            for (let i = 0; i < filesInfo.length; i++) {
                console.log(filesInfo[i]);
                box_html += "<span class=\"upload_icon_all\"></span>" + filesInfo[i].name;
                box_html += "<span class=\"emoji emoji274c\" onclick=\"delFile(" + i +")\"></span>";
            }
            box_html += "</div>"
            console.log(box_html);
            document.getElementById('files_box').innerHTML = box_html;
        }

        function teacherLevelSel() {
            var level_sel = $('#select_teacherLvl').val()-1;
            var tuition_std = $('#input_tuition_std').val();
            var hours = $('#input_hours').val();
            var std = JSON.parse(tuition_std);
            var std_total = std[level_sel]*hours;
            console.log('hours:' + hours);
            console.log('tuition_std:' + tuition_std);
            console.log('std:' + std);
            console.log('std_total:' + std_total);
            $('#input_total').val(std_total);
            var level_str = ['副高', '正高', '院士专家'];
            var hint = '[提示] '+level_str[level_sel]+'级老师 每学时最高不超过'+std[level_sel]+'元, '+hours+'学时总共不超过'+std_total+'元';
            if(hours == "")
                document.getElementById("span_std_hint").innerText = '请输入课时!';
            else
                document.getElementById("span_std_hint").innerText = hint;
        }

        function calc() {
            var i1 = document.getElementById('input_price').value;
            var i2 = document.getElementById('input_quantity').value;
            if (i1 && i2) {
                var r = document.getElementById('input_total');
                var f = parseFloat(i1 * i2);
                r.value = f.toFixed(2);
                //r.style.display = 'block';
            }
        }
    </script>
</block>
